'use client';

import NavLinks from "@/components/ui/Dashboard/Sidebar/NavLinks/NavLinks";
import {usePathname, useRouter} from "next/navigation";
import Link from "next/link";
import styles from "./Sidebar.module.css";
import WeatherWidget from "@/components/ui/Dashboard/WeatherWidget/WeatherWidget";
import Button from "@/components/ui/Button/Button";
import {logoutUser} from "@/lib/data";

export default function Sidebar() {
    const {replace} = useRouter();
    const pathname = usePathname()

    const handleLogout = async () => {
        await logoutUser();
    };

    return (
        <div className={styles.sidebar}>
            {pathname.startsWith("/admin") ?
                <Link href={"/admin/weather/"} className={styles.logo}>
                    (<WeatherWidget/>)
                </Link> :
                <div className={styles.logo}>
                    <h1>Добро пожаловать!</h1>
                </div>}
            <div className={styles.navSection}>
                <NavLinks/>
                <div className={styles.spacer}></div>
                <Button type="submit" kind='logout' content="Выйти" onClick={handleLogout}></Button>
            </div>
        </div>
    );
}
